$(function() {
	var isTureCode='';
	
	/*验证码样式	*/
	function getStyle(){
		var code=[0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
		var codeColor=['darkturquoise','rebeccapurple','sandybrown','magenta','#000'];
		var codebgColor=['lightcoral','goldenrod','lightblue','red','green','blue','yellow','orange','olive','darkturquoise'];
		var numbgColor=Math.floor( Math.random()*10);
		$(".code").css({"background-color":codebgColor[numbgColor]})
		var num0=Math.floor(Math.random()*62);
		var num1=Math.floor(Math.random()*62);
		var num2=Math.floor(Math.random()*62);
		var num3=Math.floor(Math.random()*62);
		var num=code[num0]+''+code[num1]+''+code[num2]+''+code[num3];
		isTureCode=num;
		$(".code").html(num);
		$(".code i").css({"background-color":codebgColor[numbgColor]})		
	}
	getStyle();
	$(".code").click(()=>{
		getStyle();
	})
/*点击确定判断*/		
	$("input[type='button']").click(function() {
		var userName = $("input[name='user']").val();
		var password = $("input[name='password']").val();
		var bycode = $("input[name='bycode']").val();
		if(userName){
			if(password){
				if(bycode){
					if(bycode==isTureCode){
						getAjax();
					}else{
						alert('您的输入验证码有误')
					}
				}else{
					alert('请您完善验证码')
				}								
			}else{
				alert('请您完善密码')
			}
		}else{
			alert('请您完善用户名')
		}
		
		
		
	});
	/*登录请求ajax*/
	function getAjax(){
		var userName = $("input[name='user']").val();
		var password = $("input[name='password']").val();
		$.ajax({
			url : path + "/userServlet",
			type : "post",
			data : {
				method : 'Login',
				user : userName,
				password : password
			},
			dataType : "text",
			success : function(data) {
				if (data == "false") {
					alert("登陆失败");
				} else {
					window.location.href = "main.jsp";
				}
			},
			error : function(data) {
				alert("登陆失败")
			}
		})
	}

	
	
	
	
	
})